<template>
  <div class="container">
    <el-row class="">
      <el-col :span="20" align="left">
        <el-input
          clearable
          v-model="search.processDefName"
          placeholder="流程信息"
          style="width: 120px; margin-right: 15px"
        >
        </el-input>

        <el-input
          clearable
          v-model="search.taskName"
          placeholder="当前环节"
          style="width: 120px; margin-right: 15px"
        >
        </el-input>

        <el-button class="ordinary" @click="getTableList">搜索</el-button>
      </el-col>
      <el-col :span="4" align="right">
        <el-button class="ordinary" @click="back">返回</el-button>
      </el-col>
    </el-row>
    <div>
      <Table
        :loading="isLoading"
        :tableArr="tableDate"
        :pagination="pagination"
        :columns="columns"
        :width="100"
        :pageSize="pagination.limit"
        :showSize="true"
        :isCheckbox="true"
        :total="pagination.total"
        @currentChange="currentChange"
      >
        <template #operate="{ row }" width="20">
          <el-button size="small" class="ordinary" @click="handleEdit(row)">详情</el-button>
        </template>
      </Table>
    </div>
    <!-- 审查上报流程详情 -->
    <el-dialog
      v-model="reportDialog"
      width="60%"
      title="审查上报详情"
      @close="handleClose"
    >
      <el-tabs v-model="activeName" class="demo-tabs box">
        <el-tab-pane label="基本信息" name="1">
          <Information
            title="审查上报详情"
            ref="reportRef"
          ></Information>
        </el-tab-pane>
        <el-tab-pane
          label="流程图"
          name="2"
        >
          <flowChart v-if="reportDialog" :processInstanceId="processInstanceId"></flowChart>
        </el-tab-pane>
      </el-tabs>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="reportDialog = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
// import SelectOption from '@/views/science/components/selectOption/index.vue'
import Table from '@/views/science/components/table/table.vue'
import moment from 'moment'
import { getDealTables } from '../science/api/homePage'
import Information from '@/views/project/review-acceptance/progress-examine/components/information.vue'
import flowChart from '@/components/PublicProcess/Chart/flowChart.vue'
import { getDetail } from '@/views/project/api/examine'
import { servicesLoading } from '@/utils/loading'

import { onMounted, reactive, toRefs } from 'vue'
import tableHead from './dealHeader.json'
import { useStore } from 'vuex'

export default {
  components: {
    Information,
    flowChart,
    Table,
  },
  setup(props, { emit }) {
    // 发送请求
    onMounted(() => {
      // 获取数据字典
      // getCodeList();
      getTableList()
    })
    const store = useStore()

    let data = reactive({
      id: '',
      flag: 1,
      infoDialog: false,
      ids: [],
      reportDialog: false,
      pagination: { page: 1, limit: 10, total: 0 }, //分页
      isLoading: false,
      unitNameList: [],
      awardList: [],
      tableDate: [],
      columns: tableHead.dealsHeader,
      search: {
        processDefName: '',
        taskName: '',
      },
      activeName:'1',
      processInstanceId:''
    })

    // 获取列表信息
    let getTableList = () => {
      ;(data.isLoading = true),
        getDealTables({
          page: data.pagination.page,
          size: data.pagination.limit,
          ...data.search,
        })
          .then((res) => {
            let resData = res.data.data.records
            resData.map((item) => {
              if (item) {
                item.createTime = moment(item.createTime).format('YYYY-MM-DD')
              }
            })
            data.tableDate = res.data.data.records
            data.pagination.total = res.data.data.total
            data.isLoading = false
          })
          .catch((err) => {
            data.isLoading = false
          })
    }

    // 分页

    let currentChange = (current) => {
      data.pagination.page = current

      getTableList()
    }

    // 编辑

    let handleEdit = (row) => {
        console.log(row,'handleEdit');
      if (row.taskId == '0') {
        detailData(row.businessId)
      } else {
        emit('changeProcess', row, '1')
      }
    }
    //详情数据获取
    const detailData = async (id) => {
      const loading = servicesLoading({ fullscreen: false })
      let res = await getDetail(id)
      console.log(res.data, 'res.data')
      if (res.data.success) {
        const resData = res.data.data
        store.commit('projectCenter/getReportDetailForm', { ...res.data.data })
        data.reportDialog = true
        data.processInstanceId = resData.processInstanceId
        loading.close()
      }
    }
    const handleClose = () => {
      data.activeName = '1'
    }
    let back = () => {
      emit('changeBoard')
    }

    return {
      ...toRefs(data),
      handleClose,
      handleEdit,
      back,
      getTableList,
      currentChange,
    }
  },
}
</script>
<style lang="scss">
.conUnitName {
  display: inline-block;
  width: 200px;
}

.container {
  background-color: white !important;
  padding: 20px;
}

.gy-cascader {
  .el-cascader-node {
    max-width: 250px;
  }
}
</style>
